
def d(n):
    ret = 0
    for i in range(1, n):
        if n % i == 0:
            ret += i
    return ret

t0 = []

for i in range(1, 10000):
    di = d(i)
    if di != i:
        t0.append((i, di))

t = set()
for i, j in t0:
    if (j, i) in t0:
        print i, j
        t.add(i)
        t.add(j)

print sum(t)